package com.showsu.editor.utils;

import com.showsu.editor.entity.doo.RemoteInterfaceInfo;
import com.showsu.editor.entity.platform.xhs.XhsAwemeDetailResult;
import com.showsu.editor.entity.remote.WhoseCardVideoDetailResp;
import com.showsu.editor.entity.tikhub.TikhubXhsAwemeCommentListResp;
import com.showsu.editor.enums.RemoteInterfaceEnum;
import com.showsu.editor.enums.RemoteInterfacePlatformEnum;
import com.showsu.editor.enums.StandbyEnum;
import com.showsu.editor.service.IRemoteInterfaceInfoService;
import com.showsu.editor.utils.remote.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author: William
 * @Description: 核心业务调用平台接口集成工具
 * @Date: Created in 11:27 上午 2024/9/14
 * @Modified By:
 */
@Slf4j
@Component
public class RemoteIntegrationUtil {

    @Autowired
    private IRemoteInterfaceInfoService remoteInterfaceInfoService;

    @Autowired
    private ApifoxUtil apifoxUtil;

    @Autowired
    private Boy235Util boy235Util;

    @Autowired
    private DataShopUtil dataShopUtil;

    @Autowired
    private SocialscrapeUtil socialscrapeUtil;

    @Autowired
    private R124Util r124Util;

    @Autowired
    private R202Util r202Util;

    @Autowired
    private MoreAPIProUtil moreAPIProUtil;

    @Autowired
    private SelfAPIUtil selfAPIUtil;

    @Autowired
    private NewR52Util newR52Util;

    @Autowired
    private ApptimesUtil apptimesUtil;

    @Autowired
    private BatmkeyUtil batmkeyUtil;

    @Autowired
    private BatmkeyPrivateUtil batmkeyPrivateUtil;

    @Autowired
    private TikhubUtil tikhubUtil;

    @Autowired
    private ApiOkUtil apiOkUtil;

    @Autowired
    private DatapiUtl datapiUtl;

    @Autowired
    private TutuAPIUtil tutuAPIUtil;

    @Autowired
    private ApiServerUtil apiServerUtil;


    /**
     * 获取dy作品详情live版
     * 使用目前在用的接口
     * @param awemeId 作品id
     * @return
     */
    public WhoseCardVideoDetailResp getDyAwemeDetailForLive(String awemeId) {
        RemoteInterfaceInfo remoteInterfaceInfo = remoteInterfaceInfoService.queryUsingInterfaceInfo(RemoteInterfaceEnum.DY_AWEME_DETAIL_FOR_LIVE.toString().toLowerCase());
        return getDyAwemeDetailForLive(awemeId, remoteInterfaceInfo);
    }

    /**
     * 获取dy作品详情live版
     * 使用目前在用的接口
     * @param awemeId 作品id
     * @return
     */
    public WhoseCardVideoDetailResp getDyAwemeDetailForLive(String awemeId,RemoteInterfaceInfo remoteInterfaceInfo) {
        switch (remoteInterfaceInfo == null ? RemoteInterfacePlatformEnum.DEFAULT : RemoteInterfacePlatformEnum.getByCode(remoteInterfaceInfo.getPlatform())) {
            case TIKHUB:
                return tikhubUtil.getDyVideoDetailByProxy(awemeId, remoteInterfaceInfo.getInterfaceId());
            case MOREAPIPRO:
                return moreAPIProUtil.getDyAwemeDetail(awemeId, remoteInterfaceInfo.getInterfaceId());
            case SELFAPI:
                return selfAPIUtil.getDyAwemeDetail(awemeId, remoteInterfaceInfo.getInterfaceId());
            case APIOK:
                return apiOkUtil.getDyAwemeDetail(awemeId, remoteInterfaceInfo.getInterfaceId());
            case R52:
            default:
                return newR52Util.getDyAwemeDetail(awemeId, remoteInterfaceInfo!=null?remoteInterfaceInfo.getInterfaceId():137);
        }
    }

    /**
     *  获取dy作品详情live版
     * 使用指定接口
     * @param awemeId 作品id
     * @return
     */
    public WhoseCardVideoDetailResp getDyAwemeDetailForLive(String awemeId, Long interfaceId) {
        RemoteInterfaceInfo remoteInterfaceInfo = remoteInterfaceInfoService.queryById(interfaceId);
        return getDyAwemeDetailForLive(awemeId, remoteInterfaceInfo);
    }


    /**
     * 查询xhs笔记详情，这个主要是用于获取Live实况图链接的
     * 指定接口
     * @param noteId
     * @return
     */
    public XhsAwemeDetailResult getXhsAwemeDetailForLive(String noteId, String xSecToken, Long interfaceId) {
        RemoteInterfaceInfo remoteInterfaceInfo = remoteInterfaceInfoService.queryById(interfaceId);
        return getXhsAwemeDetailForLive(noteId, xSecToken, remoteInterfaceInfo);
    }

    /**
     * 查询xhs笔记详情，这个主要是用于获取Live实况图链接的
     * 使用目前在用的接口
     * @param noteId
     * @return
     */
    public XhsAwemeDetailResult getXhsAwemeDetailForLive(String noteId, String xSecToken) {
        RemoteInterfaceInfo remoteInterfaceInfo = remoteInterfaceInfoService.queryUsingInterfaceInfo(RemoteInterfaceEnum.XHS_AWEME_DETAIL_FOR_LIVE.toString().toLowerCase());
        return getXhsAwemeDetailForLive(noteId, xSecToken, remoteInterfaceInfo);
    }

    /**
     * 查询xhs笔记详情，这个主要是用于获取Live实况图链接的
     * @param noteId
     * @param xSecToken 部分接口需要这个字段
     * @return
     */
    private XhsAwemeDetailResult getXhsAwemeDetailForLive(String noteId, String xSecToken, RemoteInterfaceInfo remoteInterfaceInfo) {
        switch (remoteInterfaceInfo == null ? RemoteInterfacePlatformEnum.DEFAULT : RemoteInterfacePlatformEnum.getByCode(remoteInterfaceInfo.getPlatform())) {
            case APIFOX:
                return apifoxUtil.getXhsAwemeDetail(noteId, remoteInterfaceInfo.getInterfaceId());
            case BOY235:
                switch (StandbyEnum.getByCode(remoteInterfaceInfo.getStandby())) {
                    case STANDBY1:
                        return boy235Util.getXhsAwemeDetailFromPC(noteId, remoteInterfaceInfo.getInterfaceId());
                    case NO:
                    default:
                        return boy235Util.getXhsAwemeDetail(noteId, remoteInterfaceInfo.getInterfaceId());
                }
            case DATASHOP:
                return dataShopUtil.getXhsAwemeDetail(noteId, remoteInterfaceInfo.getInterfaceId());
            case SOCIALSCRAPE:
                return socialscrapeUtil.getXhsAwemeDetail(noteId, remoteInterfaceInfo.getInterfaceId());
            case R124:
                return r124Util.getXhsAwemeDetail(noteId, remoteInterfaceInfo.getInterfaceId());
            case R202:
                switch (StandbyEnum.getByCode(remoteInterfaceInfo.getStandby())) {
                    case STANDBY1:
                        return r202Util.getXhsAwemeDetail3(noteId, remoteInterfaceInfo.getInterfaceId());
                    default:
                        return r202Util.getXhsAwemeDetail1(noteId, remoteInterfaceInfo.getInterfaceId());
                }
            case MOREAPIPRO:
                switch (StandbyEnum.getByCode(remoteInterfaceInfo.getStandby())) {
                    case STANDBY1:
                        return moreAPIProUtil.getXhsAwemeDetail(noteId, remoteInterfaceInfo.getInterfaceId());
                    default:
                        return moreAPIProUtil.getXhsAwemeDetail2(noteId, xSecToken, remoteInterfaceInfo.getInterfaceId());
                }
            case SELFAPI:
                switch (StandbyEnum.getByCode(remoteInterfaceInfo.getStandby())) {
                    case STANDBY1:
                        return selfAPIUtil.getXhsAwemeDetail(noteId, remoteInterfaceInfo.getInterfaceId());
                    default:
                        return selfAPIUtil.getXhsAwemeDetail2(noteId, xSecToken, remoteInterfaceInfo.getInterfaceId());
                }
            case R52:
                return newR52Util.getXhsAwemeDetail(noteId, xSecToken, remoteInterfaceInfo.getInterfaceId());
            case APPTIMES:
                return apptimesUtil.getXhsAwemeDetail(noteId, xSecToken, remoteInterfaceInfo.getInterfaceId());
            case BATMKEY_PUBLIC:
                return batmkeyUtil.getXhsAwemeDetail(noteId, remoteInterfaceInfo.getInterfaceId());
            case BATMKEY_PRIVATE:
            default:
                switch (remoteInterfaceInfo == null ? StandbyEnum.NO : StandbyEnum.getByCode(remoteInterfaceInfo.getStandby())) {
                    case STANDBY1:
                        return batmkeyPrivateUtil.getXhsAwemeDetail2(noteId, remoteInterfaceInfo.getInterfaceId());
                    case STANDBY2:
                        return batmkeyPrivateUtil.getXhsAwemeDetail3(noteId, remoteInterfaceInfo.getInterfaceId());
                    case NO:
                    default:
                        return batmkeyPrivateUtil.getXhsAwemeDetail(noteId, remoteInterfaceInfo == null ? Constant.INTERFACEID_BATMKEYPRIVATE_API_XHS_NOTE_DETAIL_4_LIVE : remoteInterfaceInfo.getInterfaceId());
                }
        }
    }

    /**
     * xhs作品评论live数据
     * @param noteId
     * @param cursor ⾸次传空 翻⻚是最后⼀个评论id
     * @return
     */
    public TikhubXhsAwemeCommentListResp getXhsAwemeCommentListForLive(String noteId, String cursor) {
        RemoteInterfaceInfo remoteInterfaceInfo = remoteInterfaceInfoService.queryUsingInterfaceInfo(RemoteInterfaceEnum.XHS_AWEME_COMMENT_LIST_FOR_LIVE.toString().toLowerCase());
        switch (remoteInterfaceInfo == null ? RemoteInterfacePlatformEnum.DEFAULT : RemoteInterfacePlatformEnum.getByCode(remoteInterfaceInfo.getPlatform())) {
            case DATAPI:
                return datapiUtl.getXhsAwemeCommentList(noteId, cursor, remoteInterfaceInfo.getInterfaceId());
            case APPTIMES:
                return apptimesUtil.getXhsAwemeCommentList(noteId, cursor, remoteInterfaceInfo.getInterfaceId());
            case TUTUAPI:
                return tutuAPIUtil.getXhsAwemeCommentList(noteId, cursor, remoteInterfaceInfo.getInterfaceId());
            case BATMKEY_PUBLIC:
                return batmkeyUtil.getXhsAwemeCommentList(noteId, cursor, remoteInterfaceInfo.getInterfaceId());
            case BATMKEY_PRIVATE:
                return batmkeyPrivateUtil.getXhsAwemeCommentList(noteId, cursor, remoteInterfaceInfo.getInterfaceId());
            case APISERVER:
                return apiServerUtil.getXhsAwemeCommentList(noteId, cursor, remoteInterfaceInfo.getInterfaceId());
            default:
                return null;
        }
    }
}
